<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "api".
 *
 * @property string $apiId
 * @property string $fkProjectId
 * @property string $functionName
 * @property string $apiName
 * @property string $remark
 * @property string $apiUrl
 * @property string $returnResult
 * @property string $number
 * @property string $params
 * @property string $returnParams
 * @property string $type
 * @property integer $userId
 * @property string $lastTime
 */
class Api extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'api';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['fkProjectId','apiName', 'apiUrl', 'number', 'userId', 'lastTime','returnResult'], 'required'],
            [['fkProjectId', 'userId'], 'integer'],
            [['params', 'returnParams','apiDiscribe','returnResult','remark'], 'string'],
            [['lastTime'], 'safe'],
            [['functionName'], 'string', 'max' => 50],
            [['apiName'], 'string', 'max' => 50],
            [['number', 'type'], 'string', 'max' => 20],
            [['apiUrl'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'apiId' => '接口ID',
            'fkProjectId' => '项目ID',
            'functionName' => '方法名称',
            'apiName' => '接口名称',
            'apiUrl' => '接口链接',
            'number' => '接口编号',
            'params' => '请求参数',
            'returnParams' => '返回参数',
            'returnResult' => '返回结果',
            'type' => '请求类型',
            'userId' => '用户ID',
            'lastTime' => '最后一次修改时间',
            'apiDiscribe' => '接口描述',
            'remark' => '接口备注',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getProject()
    {
        return $this->hasOne(Project::className(), ['projectId' => 'fkProjectId']);
    }

    public function validateName($attribute, $params){
        $this->addError($attribute, 'Incorrect username or password.');
    }
}
